package org.unisannio.sc;

import java.util.List;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ContactAdapter extends ArrayAdapter<Contact> {

	private Activity context;
	private List<Contact> contacts;
	public ContactAdapter(Activity context, int resource, List<Contact> contacts) {
		super(context, resource, contacts);
		this.context = context;
		this.contacts=contacts;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View row=convertView;
		if(row==null){
			LayoutInflater inflater=context.getLayoutInflater();
			row=inflater.inflate(R.layout.grid, parent, false);
			
		}
		
		TextView name= (TextView) row.findViewById(R.id.display_name);
		name.setText(contacts.get(position).getName());
		TextView number= (TextView) row.findViewById(R.id.data1); 
		number.setText(contacts.get(position).getNumber());
		ImageView icon= (ImageView) row.findViewById(R.id.icon);
		String label= contacts.get(position).getLabel();
		if(label.equalsIgnoreCase("shared")){
			icon.setImageResource(R.drawable.ic_menu_cc);
		}
		else{
			icon.setImageResource(R.drawable.ic_menu_blocked_user);
		}
		
		return row;
	}

	
	
	
}
